/*	This software is under  GNU GENERAL PUBLIC LICENSE Version 2, June 1991
*	for more information read COPYING.TXT
*	Dimitri Sean Ribeiro - 5118549
*/

//include section
#include "parser.h"

/*
 *	this function parse the command line by spliting the words
 *
 */
 
void parse_command_line (char *buffer, command_line_t *command_line)
{
	char *argz;
	size_t argz_length;

	//get argz and break on the white spaces
	if (argz_create_sep (buffer, ' ', &argz, &argz_length)) {
		perror ("Failed");
		exit (EXIT_FAILURE);
	}
  
	//get the number of commands on argz (argc)
	command_line->argc = argz_count (argz, argz_length);
	command_line->argv = (char **) malloc ((command_line->argc +1) * sizeof(char *));
	
	//get the argz (argv) commands
	argz_extract (argz, argz_length, command_line->argv);
}
